//
//  PHAsset+GIF.swift
//  GifUsage
//
//  Created by han on 2020/12/21.
//  Copyright © 2020 Ting Han. All rights reserved.
//

import UIKit
import Photos

extension PHAsset {
    var isGIF: Bool {
        return gifResource != nil
    }
    
    var gifResource: PHAssetResource? {
        let resources = PHAssetResource.assetResources(for: self)
        var resourceGIF: PHAssetResource? = nil
        for resource in resources {
            if resource.uniformTypeIdentifier == "com.compuserve.gif" {
                resourceGIF = resource
                break
            }
        }
        return resourceGIF
    }
    
    var isVideo: Bool {
        self.mediaType == .video
    }
    
    var isAudio: Bool {
        mediaType == .audio
    }
    
    var isLivePhoto: Bool {
        mediaSubtypes.contains(.photoLive)
    }
    
}
